package badugabot;

import badugaclient.PlayerInfo;

public class BotInfo extends PlayerInfo
{
	public void setBotCardChange() 
	{
		String[] keepIt = botComparison(getHand());
		for(int i=0; i<4; i++)
		{
			if(getHand().substring(2*i, 2*i+2).equals(keepIt[i]))
			{
				setCardsToChange("F", i);
			}
			else
			{
				setCardsToChange("T", i);
			}
		}
	}

	public String[] botComparison(String hand)
	{
		String[] temp = new String[4];
		String[] ranks = new  String[4];
		String[] suits = new String[4];
		for(int i=0; i<4; i++)
		{
			ranks[i] = hand.substring(i*2, i*2+1);
			suits[i] = hand.substring(i*2+1, i*2+2);
		}
		final String[] allRanks = {"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
		int[] allRanksPlace = new int[4];
		for(int i=0; i<allRanksPlace.length; i++)
		{
			for(int j=0; j<allRanks.length; j++)
			{
				if(ranks[i].equals(allRanks[j]))
				{
					allRanksPlace[i] = j;
				}
			}
		}
		for(int i=0; i<ranks.length; i++)
		{
			// if card have same suit with some other card then
			if(suits[i%4].equals(suits[(i+1)%4]) || suits[i%4].equals(suits[(i+2)%4]) || suits[i%4].equals(suits[(i+3)%4]))
			{
				// if card have same rank with some other card then
				if(ranks[i%4].equals(ranks[(i+1)%4]) || ranks[i%4].equals(ranks[(i+2)%4]) || suits[i%4].equals(ranks[(i+3)%4]))
				{
					// check if card is highest rank; if is remove it, else leave it be
					if(allRanksPlace[i%4] > allRanksPlace[(i+1)%4] || allRanksPlace[i%4] > allRanksPlace[(i+2)%4] || allRanksPlace[i%4] > allRanksPlace[(i+3)%4])
					{
						allRanksPlace[i] = -1;
					}
				}
				// if card have only same suit with some other card then
				else
				{
					// check if card is highest rank; if is remove it, else leave it be
					if(allRanksPlace[i%4] > allRanksPlace[(i+1)%4] || allRanksPlace[i%4] > allRanksPlace[(i+2)%4] || allRanksPlace[i%4] > allRanksPlace[(i+3)%4])
					{
						allRanksPlace[i] = -1;
					}
				}
			}
			// if card have same rank with some other card then
			else if(ranks[i%4].equals(ranks[(i+1)%4]) || ranks[i%4].equals(ranks[(i+2)%4]) || suits[i%4].equals(ranks[(i+3)%4]))
			{
				// check if card is highest rank; if is remove it, else leave it be
				if(allRanksPlace[i%4] > allRanksPlace[(i+1)%4] || allRanksPlace[i%4] > allRanksPlace[(i+2)%4] || allRanksPlace[i%4] > allRanksPlace[(i+3)%4])
				{
					allRanksPlace[i] = -1;
				}
			}
		}
		for(int i=0; i<ranks.length; i++)
		{
			if(allRanksPlace[i] != -1)
			{
				temp[i] += ranks[i];
				temp[i] += suits[i];
			}
			else
			{
				temp[i] = null;
			}
		}
		return temp;
	}
}
